package com.eaoa.uc.document.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.constants.AttachmentConstants;
import com.eaoa.query.pub.PubDocumentQuery;
import com.eaoa.uc.document.form.PubdocumentForm;
import com.eaoa.utils.AttachmentUtils;
import com.eaoa.vo.pub.PubDocument;
import com.stony.core.util.CoreUtils;

public class PubDocumentModifyPreAction extends EABaseAction {

	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		PubdocumentForm myform = (PubdocumentForm) form;
		
		Long documentno = CoreUtils.parseLong(myform.getDocumentno());

		if (documentno!=null) {

			if (!isReEntry(request)) {
				PubDocument po = PubDocumentQuery.loadByNo(new Long(myform
						.getDocumentno()));
				myform.setVO(po);
			}
			
			Map attachments = AttachmentUtils.getAttachmentMap(AttachmentConstants.ATTACHMENTTYPE_DOCUMENT,documentno);
			request.setAttribute("attachments", attachments);
		}
		
		return mapping.findForward("success");

	}
}
